﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Yunwei.DAL;
using Yunwei.Domain.Models;
using Yunwei.IBizLogic;

namespace Yunwei.BizLogic
{
    public class VendorIngredientService : BaseService<VendorIngredient>, IVendorIngredientService
    {
        public VendorIngredientService()
            : base(RepositoryFactory.VendorIngredientRepository)
        {
        }


        public IQueryable<VendorIngredient> FindList(int number, string name, int vendor_Id, int orderCode)
        {
            return FindPageList(out number, 1, number, name, vendor_Id, orderCode);
        }

        public IQueryable<VendorIngredient> FindPageList(out int totalRecord, int pageIndex, int pageSize, string name, int vendor_Id, int order)
        {
            IQueryable<VendorIngredient> _commonModels = CurrentRepository.Entities;
            if (!string.IsNullOrEmpty(name)) _commonModels = _commonModels.Where(cm => cm.Name.Contains(name));
            if (vendor_Id > 0) _commonModels = _commonModels.Where(vi => vi.Vendor_Id == vendor_Id);

            _commonModels = Order(_commonModels, 1);
            totalRecord = _commonModels.Count();
            return PageList(_commonModels, pageIndex, pageSize).AsQueryable();
        }

        public IQueryable<VendorIngredient> Order(IQueryable<VendorIngredient> entitys, int orderCode)
        {
            switch (orderCode)
            {
                //默认排序
                default:
                    entitys = entitys.OrderByDescending(cm => cm.Name);
                    break;
            }
            return entitys;
        }
    }
}
